<?php
class classPage
{
	//$this->pagesize	每页信息数量
	//$this->limit1		分页limit起始值
	//$this->pages		总页数
	//$this->page		当前页
	//$this->prevpage	上一页
	//$this->nextpage	下一页
	//$this->homepage	首页
	//$this->lastpage	末页
	//$this->strQuery	不带页数的查询字符串
	//$this->buttonClass	按钮的样式
	//$this->textClass	文本的样式
	
	/** classPage 主方法 
	* param totalNum			信息总数
	* param pagesize			每页信息条数
	* param method			分页参数提交方式	post/get 默认为get
	* param strPageParam		代表当前页数的变量名称 默认为'page'
	* return Void
	*/
	function classPage($totalNum,$pagesize=10,$method='get',$strPageParam='page')
	{
		$this->totalNum=$totalNum;
		$this->pagesize=$pagesize;
		$this->pages=ceil(intval($this->totalNum)/intval($this->pagesize));
		$this->method=$method;
		$this->strPageParam=$strPageParam;
		$this->buttonClass='p7';
		
		if($method=='get')
		{
			$this->page=$_GET[$strPageParam];
		}
		else
		{
			$this->page=$_POST[$strPageParam];
		}
		if(empty($this->page) || $this->page<1)
		{
			$this->page=1;
		}
		if($this->page>$this->pages)
		{
			$this->page=$this->pages;
		}
		$this->limit1=$pagesize*($this->page-1);
		$this->strQuery='?';
		if(is_array($_GET))
		{
			foreach($_GET as $key => $value)
			{
				if($key==($this->strPageParam))
				{
					continue;
				}
				if($this->strQuery=='?')
				{
					$this->strQuery.=$key.'='.$value;
				}
				else
				{
					$this->strQuery.='&'.$key.'='.$value;
				}
			}
		}
		if($this->strQuery!='?')
		{
			$this->strQuery.='&';
		}
		$this->prevpage=$this->strQuery.$this->strPageParam.'='.($this->page-1);
		$this->nextpage=$this->strQuery.$this->strPageParam.'='.($this->page+1);
		$this->homepage=$this->strQuery.$this->strPageParam.'=1';
		$this->lastpage=$this->strQuery.$this->strPageParam.'='.($this->pages);
		if($this->page>=$this->pages)
		{
			$this->nextpage='javascript:void(0)';
		}
		if($this->page<=1)
		{
			$this->prevpage='javascript:void(0)';
		}
		if($this->page==1)
		{
			$this->homepage='javascript:void(0)';
		}
		if($this->page==$this->pages)
		{
			$this->lastpage='javascript:vodi(0)';
		}
	}
	
	/**
	* 获取字符串
	*/
	function page($type=1)
	{
		switch($type)
		{
			case 1:		//易配网用户后台
				$ss='<form method="'.$this->method.'" action="'.$this->strQuery.'">
				<span class="p7">总数：<span class="fB">
						'.$this->totalNum.'
						</span></span><span class="p7"><span class="'.$this->buttonClass.'"><a href="'.$this->homepage.'">首页</a></span></span><span class="p7"><span class="'.$this->buttonClass.'"><a href="'.$this->prevpage.'">上一页</a></span></span><span class="'.$this->buttonClass.'"><a href="'.$this->nextpage.'">下一页</a></span><span class="p7"><span class="'.$this->buttonClass.'"><a href="'.$this->lastpage.'">尾页</a></span></span><span class="p7">页次：<span class="fB">
							'.$this->page.'
							/
							'.$this->pages.'
							</span></span> <span class="p7">
								<input name="'.$this->strPageParam.'" type="text" id="'.$this->strPageParam.'" style="width:30px;height:15px;"/>
								</span>
						<input type="image" src="../images/go_31.gif" style="width:31px;height:17px;line-height:17px;border:0;background:none;" align="absmiddle" onclick="goto()" /></form>';
				break;
			default:
				break;
		}
		return $ss;
	}
}
?>